package com.jian.ecommercial.service.impl;

import com.jian.ecommercial.domain.StockUser;
import com.jian.ecommercial.mapper.StockUserMapper;
import com.jian.ecommercial.service.StockUserService;
import com.jian.ecommercial.service.ex.PasswordNotMathcException;
import com.jian.ecommercial.service.ex.ServiceException;
import com.jian.ecommercial.service.ex.UsernameNotFoundException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class StockUserServiceImpl implements StockUserService {
    @Autowired
    StockUserMapper stockUserMapper;

    @Override
    public StockUser login(String username, String password) {
        StockUser stockuser = stockUserMapper.findByUsername(username);
        if (stockuser == null){
            throw  new UsernameNotFoundException("用户名不存在");
        }

        String stockuserPassword = stockuser.getPassword();
        if (!password.equals(stockuserPassword)){
            throw new PasswordNotMathcException("密码错误异常");
        }

        return stockuser;
    }
}
